<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>在线考试系统 - 注册</title>
    <link rel="stylesheet" href="/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: url('/images/login_bg.png') no-repeat center center fixed;
            background-size: cover;
            display: flex;
            justify-content: center;
            align-items: flex-start; /* 修改为顶部对齐 */
            min-height: 100vh;
            margin: 0;
            position: relative;
            padding-top: 60px; /* 添加顶部内边距 */
        }
        /* 添加动态背景 */
        .bg-bubbles {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
            overflow: hidden;
        }

        .bg-bubbles li {
            position: absolute;
            list-style: none;
            display: block;
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.15);
            bottom: -160px;
            animation: square 25s infinite;
            transition-timing-function: linear;
            border-radius: 5px;
        }

        .bg-bubbles li:nth-child(1) {
            left: 10%;
        }

        .bg-bubbles li:nth-child(2) {
            left: 20%;
            width: 80px;
            height: 80px;
            animation-delay: 2s;
            animation-duration: 17s;
        }

        .bg-bubbles li:nth-child(3) {
            left: 25%;
            animation-delay: 4s;
        }

        .bg-bubbles li:nth-child(4) {
            left: 40%;
            width: 60px;
            height: 60px;
            animation-duration: 22s;
            background-color: rgba(255, 255, 255, 0.25);
        }

        .bg-bubbles li:nth-child(5) {
            left: 70%;
        }

        .bg-bubbles li:nth-child(6) {
            left: 80%;
            width: 120px;
            height: 120px;
            animation-delay: 3s;
            background-color: rgba(255, 255, 255, 0.2);
        }

        .bg-bubbles li:nth-child(7) {
            left: 32%;
            width: 160px;
            height: 160px;
            animation-delay: 7s;
        }

        .bg-bubbles li:nth-child(8) {
            left: 55%;
            width: 20px;
            height: 20px;
            animation-delay: 15s;
            animation-duration: 40s;
        }

        @keyframes square {
            0% {
                transform: translateY(0) rotate(0deg);
                opacity: 1;
                border-radius: 0;
            }
            100% {
                transform: translateY(-1000px) rotate(720deg);
                opacity: 0;
                border-radius: 50%;
            }
        }

        .register-container {
            width: 480px;
            padding: 40px 35px;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 16px;
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
            transition: all 0.4s ease;
            z-index: 10;
            position: relative;
            overflow: hidden;
        }

        .register-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 5px;
            background: linear-gradient(to right, #3498db, #2c3e50);
        }

        .register-container:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
        }

        .form-title {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 35px;
            font-weight: 700;
            font-size: 32px;
            letter-spacing: 1px;
            position: relative;
            padding-bottom: 15px;
        }

        .form-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 4px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            border-radius: 2px;
        }

        .form-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 25px;
            gap: 20px;
        }

        .form-group {
            flex: 1;
            position: relative;
            margin-bottom: 0;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #2c3e50;
            font-weight: 600;
            font-size: 14px;
            padding-left: 5px;
        }

        .input-icon {
            position: absolute;
            left: 15px;
            top: 42px;
            color: #7f8c8d;
            font-size: 16px;
        }

        input[type="text"],
        input[type="password"],
        input[type="email"] {
            width: 100%;
            padding: 14px 15px 14px 45px;
            border: 2px solid #e0e7ff;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s;
            background: #f8faff;
            color: #2c3e50;
            font-weight: 500;
        }

        input[type="text"]:focus,
        input[type="password"]:focus,
        input[type="email"]:focus {
            border-color: #3498db;
            box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.2);
            outline: none;
            background: white;
        }

        .password-group {
            position: relative;
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 42px;
            cursor: pointer;
            color: #7f8c8d;
            transition: color 0.3s;
            font-size: 18px;
        }

        .password-toggle:hover {
            color: #3498db;
        }

        .password-mismatch {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
            font-weight: 500;
        }

        .role-section {
            background: #f8faff;
            border-radius: 10px;
            padding: 20px;
            margin: 25px 0;
            border: 2px solid #e0e7ff;
        }

        .role-section label {
            display: block;
            margin-bottom: 15px;
            color: #2c3e50;
            font-weight: 600;
            font-size: 16px;
        }

        .role-radio {
            display: flex;
            justify-content: space-between;
            margin: 0;
        }

        .role-option {
            flex: 1;
            text-align: center;
            padding: 15px 10px;
            background: white;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s;
            border: 2px solid #e0e7ff;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
        }

        .role-option:first-child {
            margin-right: 15px;
        }

        .role-option.active {
            border-color: #3498db;
            background: rgba(52, 152, 219, 0.1);
            box-shadow: 0 5px 15px rgba(52, 152, 219, 0.15);
        }

        .role-option i {
            font-size: 28px;
            color: #3498db;
        }

        .role-option span {
            font-weight: 600;
            color: #2c3e50;
            font-size: 15px;
        }

        .role-option input {
            display: none;
        }

        .error {
            color: #e74c3c;
            font-size: 15px;
            text-align: center;
            margin: 15px 0;
            padding: 15px;
            background: rgba(231, 76, 60, 0.1);
            border-radius: 10px;
            border-left: 4px solid #e74c3c;
            font-weight: 500;
        }

        button {
            width: 100%;
            padding: 16px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            color: white;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 18px;
            font-weight: 600;
            letter-spacing: 1px;
            transition: all 0.3s ease;
            margin-top: 15px;
            box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
            position: relative;
            overflow: hidden;
        }

        button::after {
            content: '';
            position: absolute;
            top: -50%;
            left: -60%;
            width: 20px;
            height: 200%;
            background: rgba(255, 255, 255, 0.3);
            transform: rotate(25deg);
            transition: all 0.4s;
        }

        button:hover::after {
            left: 120%;
        }

        button:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(52, 152, 219, 0.4);
        }

        button:active {
            transform: translateY(0);
        }

        .login-link {
            text-align: center;
            margin-top: 25px;
            color: #7f8c8d;
            font-size: 15px;
            font-weight: 500;
        }

        .login-link a {
            color: #3498db;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s;
            position: relative;
        }

        .login-link a::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: #3498db;
            transition: width 0.3s;
        }

        .login-link a:hover::after {
            width: 100%;
        }

        .login-link a:hover {
            color: #2980b9;
        }

        /* 响应式设计 */
        @media (max-width: 520px) {
            .register-container {
                width: 95%;
                padding: 30px 20px;
            }

            .form-row {
                flex-direction: column;
                gap: 15px;
                margin-bottom: 15px;
            }

            .role-option:first-child {
                margin-right: 0;
                margin-bottom: 10px;
            }

            .role-radio {
                flex-direction: column;
                gap: 10px;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .register-container {
            animation: fadeIn 0.6s ease-out;
        }
    </style>
</head>
<body>
<!-- 动态背景元素 -->
<ul class="bg-bubbles">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

<div class="register-container">
    <h2 class="form-title">用户注册</h2>

    <!-- 错误消息提示 -->
    <div th:if="${error}" class="alert alert-danger" role="alert">
        <span th:text="${error}"></span>
    </div>

    <form id="registerForm" th:action="@{/register}" method="post">
        <div class="form-row">
            <div class="form-group">
                <label for="userId"><i class="fas fa-user-tag"></i> 用户ID</label>
                <div class="input-icon"><i class="fas fa-id-card"></i></div>
                <input type="text" id="userId" name="userId" required placeholder="输入唯一ID">
            </div>

            <div class="form-group">
                <label for="userName"><i class="fas fa-user"></i> 用户名</label>
                <div class="input-icon"><i class="fas fa-signature"></i></div>
                <input type="text" id="userName" name="userName" required placeholder="输入您的姓名">
            </div>
        </div>

        <div class="form-row">
            <div class="form-group password-group">
                <label for="password"><i class="fas fa-lock"></i> 密码</label>
                <div class="input-icon"><i class="fas fa-key"></i></div>
                <input type="password" id="password" name="password" required placeholder="设置登录密码">
                <i class="password-toggle fas fa-eye" onclick="togglePassword('password')"></i>
            </div>

            <div class="form-group password-group">
                <label for="confirmPassword"><i class="fas fa-lock"></i> 确认密码</label>
                <div class="input-icon"><i class="fas fa-key"></i></div>
                <input type="password" id="confirmPassword" name="confirmPassword" required placeholder="再次输入密码">
                <i class="password-toggle fas fa-eye" onclick="togglePassword('confirmPassword')"></i>
            </div>
        </div>

        <div class="form-group">
            <label for="email"><i class="fas fa-envelope"></i> 邮箱</label>
            <div class="input-icon"><i class="fas fa-at"></i></div>
            <input type="email" id="email" name="email" required placeholder="输入有效邮箱地址">
        </div>

        <div class="role-section">
            <label><i class="fas fa-user-tie"></i> 用户类型</label>
            <div class="role-radio">
                <div class="role-option active" onclick="selectRole('student')">
                    <i class="fas fa-graduation-cap"></i>
                    <span>学生</span>
                    <input class="form-check-input" type="radio" name="role" id="roleStudent" value="student" checked>
                </div>

                <div class="role-option" onclick="selectRole('teacher')">
                    <i class="fas fa-chalkboard-teacher"></i>
                    <span>教师</span>
                    <input class="form-check-input" type="radio" name="role" id="roleTeacher" value="teacher">
                </div>
            </div>
        </div>

        <div id="passwordMismatch" class="password-mismatch">
            <i class="fas fa-exclamation-circle"></i> 两次输入的密码不一致
        </div>

        <button type="submit">
            <i class="fas fa-user-plus"></i> 立即注册
        </button>

        <div class="login-link">
            <p>已有账号? <a th:href="@{/login}">立即登录</a></p>
        </div>
    </form>
</div>

<script>
    // 切换密码可见性
    function togglePassword(fieldId) {
        const passwordField = document.getElementById(fieldId);
        const icon = passwordField.parentElement.querySelector('.password-toggle');

        if (passwordField.type === "password") {
            passwordField.type = "text";
            icon.classList.replace('fa-eye', 'fa-eye-slash');
        } else {
            passwordField.type = "password";
            icon.classList.replace('fa-eye-slash', 'fa-eye');
        }
    }

    // 密码一致性检查
    function checkPasswordMatch() {
        const password = document.getElementById('password').value;
        const confirmPassword = document.getElementById('confirmPassword').value;
        const mismatchElement = document.getElementById('passwordMismatch');
        const registerBtn = document.querySelector('button[type="submit"]');

        if (password && confirmPassword && password !== confirmPassword) {
            mismatchElement.style.display = 'block';
            registerBtn.disabled = true;
            registerBtn.style.opacity = '0.7';
            return false;
        } else {
            mismatchElement.style.display = 'none';
            registerBtn.disabled = false;
            registerBtn.style.opacity = '1';
            return true;
        }
    }

    // 添加实时检查
    document.getElementById('password').addEventListener('input', checkPasswordMatch);
    document.getElementById('confirmPassword').addEventListener('input', checkPasswordMatch);

    // 表单提交前验证
    document.getElementById('registerForm').addEventListener('submit', function(e) {
        if (!checkPasswordMatch()) {
            e.preventDefault();
            document.getElementById('passwordMismatch').style.display = 'block';
        }
    });

    // 角色选择
    function selectRole(role) {
        const studentOption = document.querySelector('.role-option:first-child');
        const teacherOption = document.querySelector('.role-option:last-child');

        if (role === 'student') {
            studentOption.classList.add('active');
            teacherOption.classList.remove('active');
            document.getElementById('roleStudent').checked = true;
        } else {
            teacherOption.classList.add('active');
            studentOption.classList.remove('active');
            document.getElementById('roleTeacher').checked = true;
        }
    }

    // 添加输入框聚焦效果
    const inputs = document.querySelectorAll('input');
    inputs.forEach(input => {
        input.addEventListener('focus', function() {
            this.parentElement.style.transform = 'translateY(-3px)';
        });

        input.addEventListener('blur', function() {
            this.parentElement.style.transform = 'translateY(0)';
        });
    });
</script>
</body>
</html>